package com.example.config;

import lombok.extern.slf4j.Slf4j;

import java.io.*;
import java.net.Socket;
import java.util.UUID;

@Slf4j
public class ChatClient {

    public static void main(String[] args) throws IOException {
        String host = "127.0.0.1";
        int port = 2323;
//        int port = 8068;
//        String host = "10.20.128.128";
//        int port = 9017;
        //与服务端建立连接
        Socket socket = new Socket(host, port);
        socket.setOOBInline(true);

        //建立连接后获取输出流
        while (true){
        DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
        DataInputStream inputStream = new DataInputStream(socket.getInputStream());
        byte[] bytes = new byte[4];
//        String uuid = UUID.randomUUID().toString() ;
//            bytes[0]=10;
//            bytes[1]=10;
//            bytes[2]=20;
//            bytes[3]=0;
//            uuid = uuid+ bytes.toString();
//            log.info("uuid: {}", uuid);
//        outputStream.write(uuid.getBytes());
            outputStream.write("10102020uu2iddddddddddddddaaaaadddddddd".getBytes());
        DataInputStream inputStream1 = new DataInputStream(socket.getInputStream());
        String content = "";

            byte[] buff = new byte[1024];
            inputStream.read(buff);
            String buffer = new String(buff, "utf-8");
//            content += buffer;
            log.info("info: {}", buffer);
//            log.info("buffer: {}", buffer);
//            File file = new File("json.json");
//            FileWriter fileWriter = new FileWriter(file);
//            fileWriter.write(content);
//            fileWriter.flush();

        }
    }
}